package com.funny.rabbitmq.deadqueue;

import com.funny.rabbitmq.utils.RabbitMQUtils;
import com.rabbitmq.client.Channel;

public class Producer {

    // 普通交换机和队列
    private final static String NORMAL_EXCHANGE_NAME = "normal.exchange";
    private final static String NORMAL_QUEUE_NAME = "normal.queue";
    private final static String ROUTING_KEY = "zhangsan";


    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMQUtils.getChannel();
        // 声明交换机
//        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.FANOUT, true);
        // 声明队列
//        channel.queueDeclare(QUEUE_NAME, true, false, false, null);
        // 将路由键与队列、交换机绑定
//        channel.queueBind(QUEUE_NAME, EXCHANGE_NAME, ROUTING_KEY);

        // 死信消息，设置TTL时间 单位是ms 10000ms=10s
       /* AMQP.BasicProperties properties = new AMQP.BasicProperties()
                .builder().expiration("10000").build();*/

        for (int i = 0; i < 10; i++) {
            String msg = "hello world_" + i;
            channel.basicPublish(NORMAL_EXCHANGE_NAME, ROUTING_KEY, null, msg.getBytes());
            System.out.println("消息发送成功");
        }
    }
}
